package com.example.flowable.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.flowable.model.TableModelConfig;

import java.util.List;

/**
 * @Classname FormModelUtils
 * @Description TODO
 * @Date 2022/8/17 22:52
 * @Created by XiongXiong
 * @Author: X.I.O
 */
public class FormModelUtils {

    public static JSONArray getFormModelArray(List<TableModelConfig> tableModelConfigList){
        JSONArray array=new JSONArray();
        for (int i = 0; i < tableModelConfigList.size(); i++) {
            TableModelConfig tableModelConfig = tableModelConfigList.get(i);
            JSONObject object=getFormModelJSON(tableModelConfig);
            array.add(object);
        }
        return array;
    }

    public static JSONObject getFormModelJSON(TableModelConfig tableModelConfig){
        return getBaseFormModelJSON(tableModelConfig.getFieldName(),
                tableModelConfig.getFieldDesc());
    }

    public static JSONObject getBaseFormModelJSON(String fieldName,String fieldNote){
        JSONObject object=new JSONObject();
                JSONObject config = new JSONObject();
                config.put("label",fieldNote);
                config.put("formId",fieldName);
                config.put("labelWidth",null);
                config.put("showLabel",true);
                config.put("changeTag",true);
                config.put("tag","el-input");
                config.put("tagIcon","input");
                config.put("defaultValue","");
                config.put("required",true);
                config.put("layout","colFormItem");
                config.put("span",24);
                config.put("document","");
                config.put("regList",new JSONArray());
        object.put("__config__",config);
                JSONObject slot=new JSONObject();
                slot.put("prepend","");
                slot.put("append","");
        object.put("__slot__",slot);
        object.put("__vModel__",fieldName);
        object.put("placeholder","请输入"+fieldNote);
                JSONObject style=new JSONObject();
                style.put("width", "100%");
        object.put("style",style);
        object.put("clearable",true);
        object.put("prefix-icon","el-icon-mobile");
        object.put("suffix-icon","");
        object.put("maxlength",11);
        object.put("show-word-limit",true);
        object.put("readonly",false);
        object.put("disabled",false);
        return object;
    }
}
